home *** CD-ROM | disk | FTP | other *** search
- /*
- File: 4D.h
- Author: K.R. Sloan, Jr.
- Last Modified: 15 August 1985
- 04 November 1986 by Karen Foltz
- Purpose: definitions for a 4D homogeneous coordinate manipulation package
- */
-
- #define X 0
- #define Y 1
- #define Z 2
- #define W 3
-
- typedef struct P4D { double P[4]; } PointType4D;
- typedef struct V4D { double V[4]; } VectorType4D;
- typedef struct T4D { double T[4][4]; } TransformType4D;
-
- /*
- ** The origin [0 0 0 1] in homogeneous coordinates.
- */
- extern PointType4D Origin;
-
- /*
- ** The smallest number distinguishable from zero due to error in calculations.
- */
- extern double epsilon;
-
- /*
- ** CreatePoint(x,y,z,w) double x,y,z,w;
- ** Return the point in homogeneous coordinates [x y z w].
- */
- extern PointType4D CreatePoint4D();
-
- /*
- ** PxT4D(P, T) PointType4D P; TransformType4D T;
- ** Multiplies a point times a transformation matrix.
- */
- extern PointType4D PxT4D();
-
- /*
- ** VxT4D(V, T) VectorType4D V; TransformType4D T;
- ** Multiplies a vector times a transformation matrix.
- */
- extern VectorType4D VxT4D();
-
- /*
- ** NormalxT4D(NormalVector, TInverse)
- **
- ** Returns a vector normal to a plane whose points are transformed
- ** by T.
- */
- extern VectorType4D NormalxT4D();
-
-
- /*
- ** TxT4D(A, B) TransformType4D A, B;
- ** Multiplies two transformation matrices.
- */
- extern TransformType4D TxT4D();
-
- /*
- ** Transpose4D(T) TransformType4D T;
- ** Finds the transpose of a matix.
- */
- extern TransformType4D Transpose4D();
-
- /*
- ** Identity4D()
- ** Returns the identity matrix.
- */
- extern TransformType4D Identity4D();
-
- /*
- ** Translate4D(V) VectorType4D V;
- ** Returns the tranformation matrix which translates by vector V.
- */
- extern TransformType4D Translate4D();
-
- /*
- ** Scale4D(P) PointType4D P;
- ** Returns the tranformation matrix which scales by [x y z w].
- */
- extern TransformType4D Scale4D();
-
- /*
- ** UniformScale4D(s) double s;
- ** Returns the tranformation matrix which scales uniformly by s.
- */
- extern TransformType4D UniformScale4D();
-
- /*
- ** Rotate4D(P0, P, Radians) PointType4D P0, P; double Radians;
- ** Returns the transformation matrix which rotates by angle "Radians"
- ** about the vector(P0,P). (use right hand rule for positive angle)
- */
- extern TransformType4D Rotate4D();
-
- /*
- ** Perspective4D(f) double f;
- */
- extern TransformType4D Perspective4D();
-
- /*
- ** CreateVector4D(a,b,c) double a,b,c;
- ** Returns the vector represented in homogeneous coordinates as [a b c 0].
- */
- extern VectorType4D CreateVector4D();
-
- /*
- ** PrintPoint4D(f,P) FILE *f; PointType4D P;
- ** Print the value of the point to the file.
- */
- extern void PrintPoint4D();
-
- /*
- ** PrintVector4D(f,v) FILE *f; VectorType4D v;
- ** Print the value of the vector to the file.
- */
- extern void PrintVector4D();
-
- /*
- ** PrintTransform4D(f,T) FILE *f; TransformType4D T;
- ** Print the value of the transformation matrix to the file.
- */
- extern void PrintTransform4D();
-
- /*
- ** Cross4D(v1,v2) VectorType4D v1,v2;
- ** Return the cross product of the two vectors: v1 X v2
- */
- extern VectorType4D Cross4D();
-
- /*
- ** Dot4D(v1,v2) VectorType4D v1,v2;
- ** Return the dot product of the two vectors: v1 . v2
- */
- extern double Dot4D();
-
- /*
- ** Normalize(V) VectorType4D V;
- ** Return a vector with the same direction, but of length 1.
- */
- extern VectorType4D Normalize();
-
-
- /*
- ** PVadd(P,V) PointType4D P; VectorType4D V;
- ** Return the point P + V
- */
- extern PointType4D PVadd();
-
- /*
- ** Ratio4D(P0,P1,t) PointType4D P0,P1; double t;
- ** Return the point specified by the parameter t on the line (P0,P1) in
- ** parametric form.
- */
- extern PointType4D Ratio4D();
-
- /*
- ** Pdiff(P1,P0) PointType4D P1,P0;
- ** Return the vector P1-P0
- */
- extern VectorType4D Pdiff();
-
- /*
- ** Vscale(s,V) double s; VectorType4D V;
- ** Return the vector s*V
- */
- extern VectorType4D Vscale();
-
- /*
- ** Vadd(V1,V2) VectorType4D V1,V2;
- ** Return the vector V1 + V2
- */
- extern VectorType4D Vadd();
-
- /*
- ** Vmag(V) VectorType4D V;
- ** Return the magnitude of the vector
- */
- extern double Vmag();
-
- /*
- ** Vneg(V), VectorType4D V;
- ** Returns the vector -V
- */
- extern VectorType4D Vneg();
-
- /*
- ** Midpoint(P1,P2), PointType4D P1,P2;
- ** Returns the midpoint of the line segment (P1, P2)
- */
- extern PointType4D Midpoint();
-
- /*
- ** NormalizePoint(P1) PointType4D *P1;
- ** Normalize P1 to the equivalent homogeneous coordinate point for which W = 1.
- */
-
- #define NormalizePoint(P1) \
- { \
- register double *p = (P1)->P; \
- register double w = p[W]; \
- \
- if (w != 1.0) {\
- /* We are assuming that the order in P is: X, Y, Z, W */ \
- *p++ /= w; *p++ /= w; *p++ /= w;\
- *p = 1.0;\
- }\
- }
-